import request from '../utils/request';

/**
 *  创建报警规则
 * @param {string} name 报警规则名称
 * @param {number} parameterId 设备参数id
 * @param {string} alarmMethod 报警比较方法
 * @param {number} alertThreshold 预警阈值
 * @param {number} alarmThreshold 报警阈值
 * @param {Boolean} active 开关状态
 */
export function createAlarmRuleApi(name, parameterId, alarmMethod, alertThreshold, alarmThreshold, active) {
  return request({
    url: '/alarm_rules',
    method: 'post',
    data: {
      name,
      parameter_id: parameterId,
      alarm_method: alarmMethod,
      alert_threshold: alertThreshold,
      alarm_threshold: alarmThreshold,
      active
    }
  });
}

/**
 * 删除报警规则
 * @param {string} uuid uuid
 */
export function deleteAlarmRuleApi(uuid) {
  return request({
    url: '/alarm_rules/' + uuid,
    method: 'delete'
  });
}

/**
 * 更新报警规则
 * @param {string} uuid 报警规则uuid
 * @param {string} name 报警规则名称
 * @param {number} parameterId 设备参数id
 * @param {string} alarmMethod 报警比较方法
 * @param {number} alertThreshold 预警阈值
 * @param {number} alarmThreshold 报警阈值
 * @param {Boolean} active 开关状态
 */
export function updateAlarmRuleApi(uuid, name, parameterId, alarmMethod, alertThreshold, alarmThreshold, active) {
  return request({
    url: '/alarm_rules/' + uuid,
    method: 'put',
    data: {
      name,
      parameter_id: parameterId,
      alarm_method: alarmMethod,
      alert_threshold: alertThreshold,
      alarm_threshold: alarmThreshold,
      active
    }
  });
}

/**
 *  获取报警规则列表
 * @param {number} pageIndex 页码下标，默认从0开始
 * @param {number} pageSize 每页大小
 * @param {string} sortType 正序or倒序
 * @param {string} name 报警规则名称，支持模糊搜索
 */
export function getAlarmRuleListApi(pageIndex, pageSize, sortType, name) {
  return request({
    url: '/alarm_rules',
    method: 'get',
    params: Object.assign(
      {
        page_index: pageIndex,
        page_size: pageSize,
        sort_type: sortType
      },
      name ? { name: name } : null
    )
  });
}

/** 获取报警规则详情接口@param {string} uuid uuid*/
export function getAlarmRuleDetailApi(uuid) {
  return request({
    url: '/alarm_rules/' + uuid,
    method: 'get'
  });
}
